package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.WhCompany;
import com.ruoyi.system.service.IWhCompanyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司配置Controller
 *
 * @author ruoyi
 * @date 2023-02-25
 */
@RestController
@RequestMapping("/system/company")
public class WhCompanyController extends BaseController {
    @Autowired
    private IWhCompanyService whCompanyService;

    /**
     * 查询公司配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(WhCompany whCompany) {
        startPage();
        List<WhCompany> list = whCompanyService.selectWhCompanyList(whCompany);
        return getDataTable(list);
    }

    /**
     * 导出公司配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:company:export')")
    @Log(title = "公司配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WhCompany whCompany) {
        List<WhCompany> list = whCompanyService.selectWhCompanyList(whCompany);
        ExcelUtil<WhCompany> util = new ExcelUtil<WhCompany>(WhCompany.class);
        util.exportExcel(response, list, "公司配置数据");
    }

    /**
     * 获取公司配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:company:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(whCompanyService.selectWhCompanyById(id));
    }

    /**
     * 新增公司配置
     */
    @PreAuthorize("@ss.hasPermi('system:company:add')")
    @Log(title = "公司配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WhCompany whCompany) {
        whCompany.setCreateBy(getUserId().toString());
        return toAjax(whCompanyService.insertWhCompany(whCompany));
    }

    /**
     * 修改公司配置
     */
    @PreAuthorize("@ss.hasPermi('system:company:edit')")
    @Log(title = "公司配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WhCompany whCompany) {
        whCompany.setUpdateBy(getUserId().toString());
        return toAjax(whCompanyService.updateWhCompany(whCompany));
    }

    /**
     * 删除公司配置
     */
    @PreAuthorize("@ss.hasPermi('system:company:remove')")
    @Log(title = "公司配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(whCompanyService.deleteWhCompanyByIds(ids));
    }
}
